import { Application } from 'egg';

interface tokenOptionsType {
  [key: string]: any
}
const createToken = (app: Application, options: tokenOptionsType = {}) => {
  return app.jwt.sign({ ...options, exp: new Date().getTime() }, app.config.jwt.secret);
};

// 判断过期时间
/*
  @params   {time}  初始时间戳
  @params   {exp}   过期时间
*/

const isExpire = (time, exp = 24 * 60 * 60 * 1000) => {
  const currentTime = new Date().getTime();
  return !(currentTime - time < exp);
};


export default {
  createToken,
  isExpire,
};
